/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataBase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author juanjo
 */
public class BaseDeDatos {

    private static Connection connection;
    private static Statement st;
    private static ResultSet rs;

    public static boolean getConexion() {
        try {
            connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/weborderciel","root", "");
            //connection = DriverManager.getConnection("jdbc:mysql://localhost:8889/weborderciel", "root", "root");

        } catch (Exception ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
            connection = null;
        }

        if (connection == null) {
            return false;
        } else {
            return true;
        }
    }

    public static ResultSet getResultSet(String query) {

        try {
            st = connection.createStatement();
            rs = st.executeQuery(query);
        } catch (Exception ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
            rs = null;
        }
        return rs;
    }

    public static void executeUpdate(String query) {
        try {
            st = connection.createStatement();
            st.executeUpdate(query);

        } catch (Exception ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);

        }
    }
}
